package cn.ilikes.tools.hbase.jpa.clients.admins;

import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import cn.ilikes.tools.hbase.jpa.clients.datasource.HbaseDataSource;
import cn.ilikes.tools.hbase.jpa.clients.datasource.JPAHBaseDataSourceRuntimeException;

/**
 * 
 * @author fack
 * 
 */
public class JPAHbaseAdmin extends AbAdminImple implements IAdmin {

	//	  private  HbaseDataSource hbaseDataSource ;

	private HBaseAdmin hBaseAdmin;

	public JPAHbaseAdmin(HbaseDataSource hbaseDataSource) {

		try {
			HBaseAdmin hbaseAdmin = new HBaseAdmin(hbaseDataSource.getHadoopConf());
			sethBaseAdmin(hbaseAdmin);
		} catch (MasterNotRunningException e) {
			throw new JPAHBaseDataSourceRuntimeException(e);
		} catch (ZooKeeperConnectionException e) {
			throw new JPAHBaseDataSourceRuntimeException(e);
		}

	}

	private void sethBaseAdmin(HBaseAdmin hBaseAdmin) {
		this.hBaseAdmin = hBaseAdmin;
	}

	@Override
	public <V> V getAdmin() {

		return (V) hBaseAdmin;
	}

}
